<template>
  <el-dialog
    :visible.sync="visible"
    :before-close="handleClose"
    title="提示"
    width="30%">
    <div style="text-align: center; color: #333">
      <p>请确认是否继续？</p>
      <p>当前操作将修改 <b>{{ user.username }}</b> 的成绩信息到及格状态。</p>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { modifyUserScore } from '@/api/education'

export default {
  name: 'Edit',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    user: {
      type: Object,
      required: true
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    submit() {
      const params = {
        user_id: this.user.user_id,
        username: this.user.username,
        kcmc: this.user.kcmc
      }

      modifyUserScore(params).then(res => {
        let type = 'error'
        if (res.code === 200) {
          type = 'success'
          this.$emit('update')
        }
        this.$message({ type, message: res.msg })
      }).finally(_ => {
        this.handleClose()
      })
    }
  }
}
</script>

<style scoped>

</style>
